<?php
/**
 * 轻云网络验证系统
 * =======================================================
 * 版权所有(C) 2019-2039 daenx.cn，并保留所有权利。
 * 作者：Daen大恩
 * 作者QQ: 1330166565
 * 开发群：661059773
 * =======================================================
 */
    include 'farmwork.php';
	header("content-type:text/html;charset=utf-8");
	login();
	
	$action = $_GET['action'];
	if($action=='do'){
		$username = $_POST['username'];
		$domain = $_POST['domain'];
		$qq = $_POST['qq'];
		$rmb = $_POST['rmb'];
		$version = $_POST['version'];
		$syskey = $_POST['syskey'];
		$yumi = $_POST['yumi'];
		$ycp = $_POST['ycp'];
		$pass = $_POST['pass'];
		$dl = $_POST['dl'];
		$bz = $_POST['bz'];
		if($_POST['time']=='free')
		{$time ="free";}
		else 
		if($_POST['time']=='')
		{$time = '';}
		else
		{$time = strtotime($_POST['time']);}
		
		
        
	    $sql="select * from authorize where domain='$domain' and ycp='$ycp'";
        $query=mysqli_query($con,$sql);
        $rows = mysqli_num_rows($query);
		if($rows > 0){
		   echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">对象已存在！</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'authorize-add.php' });  }});</script>");
		}else{
		   $sql = "INSERT INTO `authorize` (`username`,`domain`,`pass`,`qq`,`time`,`version`,`syskey`,`yumi`,`ycp`,`rmb`,`dl`,`bz`,`up`) VALUES ('$username','$domain','$pass','$qq','$time','$version','$syskey','$yumi','$ycp','$rmb','$dl','$bz','system');";
	       mysqli_query($con,$sql);
		   //mysqli_close();
		   echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">添加成功！</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'authorize.php' });  }});</script>");
		   //die;
		}
	}

$li1='class="active"';
$li11='class="active"';
?>
<?php include 'header.php';?>
    <title>添加授权-<?php echo $title?></title>
<?php include 'list.php';?>
    <!--main content start-->
    <section id="main-content">
        <section class="wrapper">
<?php include 'overview.php';?>
            <div class="row">
                <div class="col-lg-12">
                    <!--work progress start-->
                    <section class="panel">
                        <div class="panel-body progress-panel">
                            <div class="task-progress">
                                <h1>添加新授权</h1>
                                <p>填写授权信息并保存.</p>
                            </div>
                        </div>
						<form action="authorize-add.php?action=do" method="post"  role="form">
                            <div class="form-group">
                                <label for="txtDomain">产品</label>
                                <select name="ycp" class="form-control" >
								
 									<?php 
										$sql="select * from products ORDER BY `id` DESC";
										$result=mysqli_query($con,$sql);
										if($result&&mysqli_num_rows($result)){
											while ($row=mysqli_fetch_assoc($result)) {
											echo "<option value='".$row['cp']."'>".$row['cp']."</option>";											
											}
										}
									?>   
									</select>
                            </div>	
							<div class="form-group">
                                <label for="txtDomain">用户名</label>
                                <input type="text" name="username" class="form-control" placeholder="用户名" required/>
                            </div>					
                            						
                            <div class="form-group">
                                <label for="txtDomain">账号</label>
                                <input type="text" name="domain" class="form-control" placeholder="登录账号" autocomplete="off" required/>
                            </div>
                           <div class="form-group">
                                <label for="txtDomain">密码</label>
                                <input type="text" name="pass" class="form-control" placeholder="登录密码" autocomplete="off" required/>
                            </div>
							<div class="form-group">
							  <label>会员</label>
							  <select name="dl" class="form-control">
								<option value="普通用户">普通用户</option>
								<option value="VIP1">VIP1</option>
								<option value="VIP2">VIP2</option>
								<option value="VIP3">VIP3</option>
								<option value="VIP4">VIP4</option>
								<option value="VIP5">VIP5</option>
								<option value="VIP6">VIP6</option>
								<option value="VIP7">VIP7</option>
								<option value="VIP8">VIP8</option>
							  </select>
							</div>
                            <div class="form-group">
                                <label for="txtDomain">联系人QQ</label>
                                <input type="text" name="qq" class="form-control" placeholder="联系人QQ" autocomplete="off" required/>
                            </div>
                            <div class="form-group">
                                <label for="txtDomain">余额</label>
                                <input type="text" name="rmb" class="form-control" placeholder="余额" autocomplete="off" required/>
                            </div>
                            
                            <div class="form-group">
                                <label for="txtDomain"><i class="fa fa-key"></i>用户KEY<input class="btn btn-primary btn-xs" type= "button" name= "Submit1 " value= "生成" onclick= "show()"></label>
                                <input type="text" name="syskey" id="syskey"  class="form-control" placeholder="可手动输入或者点击生成" value='<?php echo $syskey?>' required/>
 					<script language=javascript> 
						function show() 
						{ 
						var str= "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" 
						var result= " " 
						for(var i=0;i <32;i++) 
						{ 
						var temp=Math.floor(Math.random()*36) 
						result+=str.charAt(temp) 
						} 
						hash = result.MD5();
						document.getElementById( "syskey").value=hash
						} 
					</script>
                            </div>
                            
							
                            <div class="form-group">
                                <label for="txtDomain">状态</label>
                                <select name="yumi" class="form-control">
                                            
                                            <option value="0">正常</option>
                                            <option value="1">禁用</option>
                                            
                                        </select>
										<span class="help-block">如果选择被禁用，那么该授权用户无法使用任何服务</span>
																			
                            </div>
							
                            <div class="form-group">
              <label>授权时间</label>
              <select name="time" class="form-control">
			  <option value="free">免费用户</option>
                <option value="+1day">天卡</option>
                <option value="+7day">周卡</option>
				<option value="+1month">月卡</option>
				<option value="+3month">季卡</option>
				<option value="+1year">年卡</option>
				<option value="">永久</option>
              </select>
            </div>
			<div class="form-group">
				<label for="txtDomain">备注</label>
				<input type="text" name="bz" class="form-control" placeholder="备注"/>
			</div>
			<div id="bottom" >
			  <button class="btn btn-info" type="submit" value="true" id="submit"/><strong>添加授权</strong></button>
            </div>
                        </form>
                    </section>
                    <!--work progress end-->
                </div>

        </section>
    </section>
    <!--main content end-->

<?php include 'footer.php';?>
